'use strict';

angular.module('swanApp').controller('SessionDialogController',
    ['$scope', '$stateParams', '$uibModalInstance', 'entity', 'Session', 'Space', 'Member', 'Event',
        function($scope, $stateParams, $uibModalInstance, entity, Session, Space, Member, Event) {

        $scope.session = entity;
        $scope.spaces = Space.query();
        $scope.members = Member.query();
        $scope.events = Event.query();
        $scope.load = function(id) {
            Session.get({id : id}, function(result) {
                $scope.session = result;
            });
        };

        var onSaveFinished = function (result) {
            $scope.$emit('swanApp:sessionUpdate', result);
            $uibModalInstance.close(result);
        };

        $scope.save = function () {
            if ($scope.session.id != null) {
                Session.update($scope.session, onSaveFinished);
            } else {
                Session.save($scope.session, onSaveFinished);
            }
        };

        $scope.clear = function() {
            $uibModalInstance.dismiss('cancel');
        };
}]);
